home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW etc / MPW-PR / Interfaces&Libraries / Interfaces / PInterfaces / Disassembler.p
Encoding:
Text File  |  1998-05-11  |  26.3 KB  |  493 lines  |  [TEXT/MPS ]

  1. {*---------------------------------------------------------------------------*
  2.  |                                                                           |
  3.  |                          <<< Disassembler.p >>>                           |
  4.  |                                                                           |
  5.  |                     Power[PC] Disassembler Interfaces                     |
  6.  |                                                                           |
  7.  |                               Ira L. Ruben                                |
  8.  |                                  5/9/93                                   |
  9.  |                                                                                                                                                     |
  10.  |                                          Translated from C to Pascal by                                             |
  11.  |                                                             Greg Branche                                                                 |
  12.  |                                                                 7/20/94                                                                     |
  13.  |                                                                           |
  14.  |                  Copyright Apple Computer, Inc. 1993-1998                 |
  15.  |                           All rights reserved.                            |
  16.  |                                                                           |
  17.  *---------------------------------------------------------------------------*}
  18.  
  19. {$IFC UNDEFINED UsingIncludes}
  20. {$SETC UsingIncludes := 0}
  21. {$ENDC}
  22.  
  23. {$IFC NOT UsingIncludes}
  24.  UNIT Disassembler;
  25.  INTERFACE
  26. {$ENDC}
  27.  
  28. {$IFC UNDEFINED __DISASSEMBLER__}
  29. {$SETC __DISASSEMBLER__ := 1}
  30.  
  31. {$I+}
  32. {$SETC DisassemblerIncludes := UsingIncludes}
  33. {$SETC UsingIncludes := 1}
  34.  
  35.  
  36. {$IFC UNDEFINED __TYPES__}
  37. {$I Types.p}
  38. {$ENDC}
  39.  
  40. {$PUSH}
  41.  
  42. CONST
  43.  
  44. {* The following defines the "options" that can be passed to the disassembler.  All    *}
  45. {* except ONE of the target architecture options have preset defaults.                            *}
  46.  
  47.                                                                                 {* Target architecture (one must be set):        *}
  48.     Disassemble_Power             = $00000001;        {*    Power                                                                    *}
  49.     Disassemble_PowerPC32     = $00000002;        {*       32-bitPowerPC                                            *}
  50.     Disassemble_PowerPC64  = $00000004;        {*          64-bit PowerPC                                     *}
  51.     Disassemble_PowerPC601 = $00000008;        {*             PowerPC 601                                    *}
  52.     Disassemble_Vec                 = $00000010;        {*               Vector                                             *}
  53.                                                                                 {* Error detection options:                         *}
  54.     Disassemble_RsvBitsErr = $80000000;        {*    invalid reserved bits is error                *}
  55.     Disassemble_FieldErr     = $40000000;        {*    invalid field (regs, BO, etc.) error    *}
  56.                                                                                 {* Formatting options (reverses presets):        *}
  57.     Disassemble_Extended     = $08000000;        {*    extended mnemonics (ppc only)                    *}
  58.     Disassemble_BasicComm     = $04000000;        {*    basic form in comment if extended            *}
  59.     Disassemble_DecSI             = $02000000;        {*    SI fields formatted as decimal                *}
  60.     Disassemble_DecUI             = $01000000;        {*    UI fields formatted as decimal                *}
  61.     Disassemble_DecField     = $00800000;        {*         fields shown as decimal                                *}
  62.     Disassemble_DecOffset     = $00400000;        {*    D of D(RA) shown in decimal                        *}
  63.     Disassemble_DecPCRel     = $00200000;        {*    $+decimal offset instead of $+hex            *}
  64.     Disassemble_DollarHex     = $00100000;        {*    $XXX... instead of 0xXXX...                        *}
  65.     Disassemble_Hex2sComp     = $00080000;        {*         negative hex shown in 2s compliment        *}
  66.     Disassemble_MinHex         = $00040000;        {*        min nbr of hex digits for values >= 0    *}
  67.     Disassemble_CRBits         = $00020000;        {*    crN_LT, crN_GT, crN_EQ, crN_SO                *}
  68.     Disassemble_CRFltBits  = $00010000;        {*        crN_FX, crN_FEX, crN_VX, crN_OX                *}
  69.     Disassemble_BranchBO     = $00008000;        {*        branch BO meaning if not extended            *}
  70.     Disassemble_TrapTO          = $00004000;        {*        trap TO meaning if not extended                *}
  71.     Disassemble_IBM                 = $00002000;        {*    IBM assembler conventions                            *}
  72.  
  73. {*
  74. Except for the target architecture options, ONE of which must be set, here's an explanation
  75. of the other options and their preset default.
  76.      
  77. Disassemble_RsvBitsErr - Reserved bits in PowerPC instructions are considered a "warning"
  78.                                                  and causes the return status to be set to indicate whether
  79.                                                  reserved bits were incorrectly coded (1's that should be 0's and
  80.                                                  vice versa). The option indicates incorrectly coded reserved bits
  81.                                                  cause the instruction to be treated as "invalid".
  82.  
  83. Disassemble_FieldErr     - Attempted use of a field value not valid for a target is
  84.                                                  considered a "warning" and causes the return status to be set to
  85.                                                  indicate that fact.  The option indicates that use of a field
  86.                                                  whose value is not valid for the target is "invalid".  An example
  87.                                                  of an invalid field would be the use of a SPR not supported for
  88.                                                  the target architecture like the "HIDx" SPRs which are only valid
  89.                                                  for the 601.  Another example is non zero bits in the bc[l][a] BO
  90.                                                  field that are supposed to be zero.  Note this is NOT the same as
  91.                                                  Disassemble_RsvBitsErr.  But if a field has NO valid decoding
  92.                                                  value for ANY target, that is always considered as an invalid
  93.                                                  instruction.
  94.  
  95. Disassemble_Extended     - Extended mnemonics are NOT generated.  The option allows the
  96.                                                  extended mnemonic generation (recommended).  Only PowerPC32,
  97.                                                  PowerPC64, and PowerPC32 and PowerPC64 instructions used on the
  98.                                                  601 are supported.
  99.  
  100. Disassemble_BasicComm     - The basic instruction form is NOT placed in the comment field.
  101.                                                  The option causes the basic form of the instruction to be placed
  102.                                                  in the comment if an extended mnemonic is generated for it.  This
  103.                                                  option is not recommended since it is mainly for debugging and it
  104.                                                  tends to "clutter" up the comment field making it harder to see
  105.                                                  branch addresses.
  106.  
  107. Disassemble_DecSI             - SIs (signed immediate integers) are formatted as hex.  The option
  108.                                                  causes SI operands to be generated as decimal integers.
  109.  
  110. Disassemble_DecUI             - UIs (unsigned immediate integers) are formatted as hex.  The
  111.                                                  option causes UI operands to be generated as decimal integers.
  112.  
  113. Disassemble_DecField     - All fields (e.g., shift/rotate constants) are shown as hex.  The
  114.                                                  option causes the offsets to be generated as decimal integers.
  115.  
  116. Disassemble_DecOffset  - The "D" offsets in operands of the form D(RA) are shown in hex.
  117.                                                  The option causes these to be generated as decimal.
  118.  
  119. Disassemble_DecPCRel     - PC-relative branch addresses are formatted as "$+n" or "$-n", with
  120.                                                  the offset ("n") generated in hex.  The option causes the offset
  121.                                                  to be generated as decimal.
  122.  
  123. Disassemble_DollarHex     - Hex values are prefixed with "0x".  The option causes hex values
  124.                                                  to be formatted as "$XXX...".
  125.  
  126. Disassemble_Hex2sComp     - Signed negative values that are shown in hex are negated and
  127.                                                  prefixed with a "-" (e.g. "-0x0001").  The option causes these
  128.                                                  values to be shown in their two's complement form (e.g.,
  129.                                                  "0xFFFFFFFF").
  130.  
  131. Disassemble_MinHex         - Positive hex values or negated negative values are always shown
  132.                                                  with the number of digits attempting to indicate the size of the
  133.                                                  instruction field which produced the value or the implied value
  134.                                                  size.  Thus 32-bit target addresses are shown as 8 hex digits,
  135.                                                  16-bit field values are shown with 4 hex digits, byte field values
  136.                                                  as 2 hex digits.  5 or six-bit values are also shown as 2 hex
  137.                                                  digits since the minimum is always at least 2. The option forces
  138.                                                  the generation to always use 2 as the minimum even if the value
  139.                                                  came from a bigger field (e.g., "0x1234" address, "0x01" or
  140.                                                  "-0x01" from a 16-bit field).
  141.  
  142. Disassemble_CRBits          - Condition register field bits are referenced as bit numbers 0:31
  143.                                                  in the basic instruction operand forms.  The option causes these
  144.                                                  bits to be referenced using the format “crN_X”, where N is a 4-bit
  145.                                                  CR field (0:7) and X is the bit “name” in the field (“LT”, “GT”,
  146.                                                  “EQ”, “SO” for bits 0, 1, 2, and 3 respectively).  Note, this
  147.                                                  notation is always used with extended mnemonics.
  148.  
  149. Disassemble_CRFltBits  - Condition register field bits are referenced as bit numbers 0:31
  150.                                                  in the basic instruction operand forms.  The option is identical
  151.                                                  to Disassemble_CRBits to generate the references as “crN_X”,
  152.                                                  except that the bits (X) are referenced as “FX”, “FEX”, “VX” and
  153.                                                  “OX” for the four bits 0,1, 2, and 3 respectively.  This option
  154.                                                  can be used if the context of floating-point operations, but it's
  155.                                                  up to the caller to determine that context.
  156.  
  157. Disassemble_BranchBO     - Branch test BO encodings are referenced as values 0:31 in the 
  158.                                                  basic instruction operand forms.  The option causes the BO value
  159.                                                  to be referenced as more meaningful names (e.g., "dCTR_NZERO_NOT",
  160.                                                  "ALWAYS", etc.).
  161.                                                  
  162. Disassemble_TrapTO         - Trap TO operand encodings are referenced as values 0:31 in the 
  163.                                                   basic instruction operand forms.  The option causes the TO value
  164.                                                  to be an expression of the form "x|y|...", where the "x", "y",
  165.                                                  and so are the meaning of each of the five TO bits; "LT", "GT",
  166.                                                  "EQ", "LOW", "HI" for bits 0, 1, 2, 3, and 4 respectively.
  167.  
  168. Disassemble_IBM                 - Apple assembler conventions are used for comments and invalid
  169.                                                  instructions.  The option causes IBM assembler conventions to be
  170.                                                  used for these.  A “#” is used instead of a “;” as the comment
  171.                                                  character, and “.long” is used instead of “dc.l” for the invalid
  172.                                                  instruction directive mnemonic.
  173.  
  174.                                   [Are we having fun yet?]
  175. *}
  176.  
  177. {* The following defines a set of the above options which seem to give "acceptable"         *}
  178. {* results:                                                                                                                                                            *}
  179.  
  180.     DisStdOptions = (Disassemble_Extended  +            {* permit extended mnemonics                *}
  181.                    Disassemble_DecSI     +            {* decimal SIs but hex UIs                    *}
  182.                    Disassemble_DecField  +            {* decimal field numbers                        *}
  183.                    Disassemble_BranchBO  +            {* meaning of branch BO                            *}
  184.                                      Disassemble_TrapTO         +            {* meaning of trap TO                                *}
  185.                                      Disassemble_CRBits);                    {* CR bits references as crN_X            *}
  186.                                              
  187.  
  188.     {* Return status flags:                                                                                                                        *}
  189.     
  190.     Disassembler_OK                      = $0001;        {* instruction successfully decoded                    *}
  191.     Disassembler_InvRsvBits      = $0002;        {* invalidly coded reserved bits                        *}
  192.     Disassembler_InvField          = $0004;        {* invalidly coded field(s)                                    *}
  193.     Disassembler_InvSprMaybe     = $0008;        {* possibly invalid SPR                                            *}
  194.     Disassembler_601Power             = $0010;        {* power instruction used with 601                    *}
  195.     Disassembler_Privileged      = $0020;        {* privileged instruction                                        *}
  196.     Disassembler_Optional          = $0040;        {* optional instruction                                            *}
  197.     Disassembler_Branch                 = $0080;        {* branch instruction                                                *}
  198.     Disassembler_601SPR                 = $0100;        {* SPR valid only for 601 has been used            *}
  199.     Disassembler_Vec                    = $0200;        {* vector instruction                                                *}
  200.     Disassembler_HasExtended  = $4000;        {* possible extended mnemonic                                *}
  201.     Disassembler_ExtendedUsed = $8000;        {* the extended mnemonic was generated            *}
  202.  
  203.     DisInvalid                                 = $0000;        {*       invalid instruction                                *}
  204.  
  205.     {*
  206.     Unless DisInvalid (0) is returned as the function result, Disassembler_OK will always be
  207.     set.  The other flags have the following meaning:
  208.     
  209.     Disassembler_InvRsvBits        - The instruction had some or all of its reserved bits
  210.                                                             incorrectly coded, and the Disassemble_RsvBitsErr option was
  211.                                                             NOT set.  This is something like a "warning". With the option
  212.                                                             set, this condition is considered as an "error" and the
  213.                                                             "invalid instruction" is generated ("dc.l 0xXXXXXXXX").
  214.     
  215.     Disassembler_InvField            -    The instruction had fields incorrectly coded for the
  216.                                                             target, but is is still valid for some target (e.g., not
  217.                                                             valid for the 601 but valid for the PowerPC64), and the
  218.                                                             Disassemble_FieldErr option was NOT set.
  219.     
  220.     Disassembler_InvSprMaybe    - A mfspr or mtspr instruction references a POSSIBLY invalid
  221.                                                             SPR.  This occurs when an SPR value is not for one of the
  222.                                                             predefined SPR names (see list above) and there is no lookup
  223.                                                             routine, or it does not supply a substitution name.  In that
  224.                                                             case the SPR register number is generated.  Since there is
  225.                                                             no way of the disassembler knowing whether the register is
  226.                                                             valid for the architecture of interest, this flag is set 
  227.                                                             instead of Disassembler_InvField to indicate the possibility
  228.                                                             that the SPR may be invalid.
  229.     
  230.     Disassembler_601Power            - The options specified that the target architecture is the
  231.                                                             601 (Disassemble_PowerPC601), and a Power instruction was
  232.                                                             disassembled.  The 601 is basically an ORing of the Power
  233.                                                             and PowerPC32 architectures.  But this flag could be useful
  234.                                                             for "weeding" Power instructions out in preparation for use
  235.                                                             on a "pure" PowerPC32 or PowerPC64 architecture.
  236.     
  237.     Disassembler_601SPR                - The options specified that the target architecture is the
  238.                                                             601 (Disassemble_PowerPC601), and a mfspr or mtspr
  239.                                                             instruction references a SPR valid ONLY for the 601.
  240.                                                     
  241.     Disassembler_Vec                    -    The instruction is a vector instruction.
  242.             
  243.     Disassembler_Privileged        - The instruction is privileged.
  244.                                                             
  245.     Disassembler_Optional            - The instruction is optional.
  246.     
  247.     Disassembler_Branch                -    Branch instruction; bc[l][a], b[l][a], bclr[l], bcctr[l] and
  248.                                                             Power bcr[l], bcc[l].  If any of these instructions are
  249.                                                             processed the flag is set.  Branches are signaled because
  250.                                                             the caller might want to do some additional processing on
  251.                                                             these.  For example, a debugger might want to dynamically
  252.                                                             show which way the branch is taken, or static analysis might
  253.                                                             want to know possible exit points from a function or show
  254.                                                             the branch in some graphical way.  Although the caller could
  255.                                                             determine if the instruction is a branch, the disassembler
  256.                                                             always has to classify the instructions passed to it, so
  257.                                                             there is no sense having both do it if the information is
  258.                                                             already available.  Note, the caller might still, however,
  259.                                                             need to extract the BO and BI fields to determine the
  260.                                                             condition of the branch, but at least it only needs to be
  261.                                                             done when the flag is set.
  262.     
  263.     Disassembler_HasExtended     - The instruction POSSIBLY has an extended mnemonic, whether
  264.                                                             used or not used (as a function of the Disassemble_Extended
  265.                                                             option). Note, "possibly has an extended mnemonic"; the
  266.                                                             instruction could have extendeds, but not for all
  267.                                                             values of its operands.
  268.                                                             
  269.     Disassembler_ExtendedUsed - The instruction has an extended mnemonic, and it was used
  270.                                                             because the option (Disassemble_Extended) permits it.  The
  271.                                                             operand is formatted appropriate to the extended mnemonic.
  272.                                                             Whether the original basic form is placed in the comment or
  273.                                                             not is controlled by the Disassemble_BasicComm option.
  274.     *}
  275.     
  276.     
  277. {* All assembler options are of type DisassemblerOptions:                                                                *}
  278.  
  279. TYPE
  280.     DisassemblerOptions =    LongInt;
  281.  
  282.     DisassemblerStatus = Integer;                                {* disassembler return status (see above)    *}
  283.  
  284. {* The optional lookup function (NULL could be passed) is used to allow the caller to        *}
  285. {* substitute name strings for various objects that can occur in an operand.  It should    *}
  286. {* return a pointer to a non-null string if substitution is desired.  If NULL or a null *}
  287. {* string is returned, the disassembler uses its own default names.  The following            *}
  288. {* defines the possible substitutable objects:                                                                                    *}
  289.  
  290.     DisassemblerLookupType    =    (                                {* Types of substitutable objects:                    *}
  291.         Disassembler_Lookup_GPRegister,                    {*            general purpose register                        *}
  292.         Disassembler_Lookup_FPRegister,                    {*            floating point register                            *}
  293.         Disassembler_Lookup_UImmediate,                    {*            unsigned immediate value                        *}
  294.         Disassembler_Lookup_SImmediate,                    {*            signed (32-bit) immediate value            *}
  295.         Disassembler_Lookup_AbsAddress,                    {*            absolute addresse                                        *}
  296.         Disassembler_Lookup_RelAddress,                    {*            relocatable addresse                                *}
  297.         Disassembler_Lookup_RegOffset,                    {*            offset from a base register                    *}
  298.         Disassembler_Lookup_SPRegister,                    {*            special purpose register                        *}
  299.         Disassembler_Lookup_VecRegister                    {*            vector register                                            *}
  300.     );
  301.  
  302.  
  303. {* Here's a definition of an object (value) which is a function of each                                 *}
  304. {* DisassemblerLookupType:                                                                                                                            *}
  305.  
  306.     {$ALIGN MAC68K}
  307.     DisLookupValue = RECORD                                        {* A "meaningful" name for each value type:    *}
  308.         CASE INTEGER OF
  309.         0:    (gpr:                    LongInt;);                        {*        Disassembler_Lookup_GPRegister                *}
  310.         1:    (fpr:                    LongInt;);                        {*        Disassembler_Lookup_FPRegister                *}
  311.         2:    (vr:                    LongInt;);                        {*        Disassembler_Lookup_VecRegister                *}
  312.         3:    (ui:                    LongInt;);                        {*        Disassembler_Lookup_UImmediate                *}
  313.         4:    (si:                    LongInt;);                        {*        Disassembler_Lookup_SImmediate                *}
  314.         5:    (absAddress:    LongInt;);                        {*        Disassembler_Lookup_AbsAddress                *}
  315.         6:    (relAddress:    LongInt;);                        {*        Disassembler_Lookup_RelAddress                *}
  316.         7:    (spr:                    LongInt;);                        {*         Disassembler_Lookup_SPRegister                *}
  317.         8:    (    {    regOffset}
  318.                     offset:            Integer;
  319.                     baseReg:        Integer;
  320.                 );                                                                    {*        Disassembler_Lookup_RegOffset                    *}
  321.     END;
  322.     {$ALIGN RESET}
  323.  
  324.     DisLookupValuePtr = ^DisLookupValue;
  325.  
  326. {* Finally, at long last, here's the definition of the disassembler...                                    *}
  327.  
  328. FUNCTION ppcDisassembler( VAR instruction     : LongInt; 
  329.                                                             dstAdjust            :    LongInt;
  330.                                                             options                :    DisassemblerOptions;
  331.                                                             mnemonic            :    CStringPtr;
  332.                                                             operand                :    CStringPtr;
  333.                                                             comment                :    CStringPtr;
  334.                                                             refCon                : UNIV Ptr;
  335.                                                             lookupRoutine    : UNIV Ptr) : DisassemblerStatus; C;
  336.     {*
  337.     Takes the four bytes pointed to by instruction and disassembles it, placing the mnemonic,
  338.     operand, and comment in the strings provided.  The caller is then free to format or use
  339.     the output strings any way appropriate to the application.  Any of these strings may be a
  340.     null pointer, in which case that portion of the disassembled instruction is not returned.
  341.     If they are not null, it is ASSUMED that the associated buffers are large enough to hold
  342.     the disassembled output.
  343.     
  344.     Comments are formatted starting with a "; " (or "#" if the appropriate "IBM" option is
  345.     set).  Invalid instructions generate a "dc.l" (".long" for IBM), an operand of the form
  346.     0xXXXXXXXX showing the actual instruction, and a comment with a message indicating what
  347.     is wrong with the instruction.
  348.     
  349.     For PC-relative branches, the comment generated is the destination address, the only
  350.     address that the disassembler "knows" about is the address of the code pointed to by the
  351.     instruction.  Generally, that may be a buffer that has no relation to "reality", i.e.,
  352.     the actual code loaded into the buffer.  Therefore, to allow the address comment to be
  353.     mapped back to some actual address, the caller may specify an adjustment factor,
  354.     specified by dstAdjust that is ADDED to the value that normally would be placed in the
  355.     comment.
  356.  
  357.     Many operands usually consist of registers, absolute and relocatable addresses, and
  358.     signed and unsigned values.  In places where these occur, the disassembler can call a
  359.     user specified routine to do the substitution using the lookupRoutine parameter if it
  360.     is not NULL.  A "refcon" is passed to the disassembler that is, in turn, passed on to
  361.     the lookup routine to allow a communication path between the disassembler caller and its
  362.     lookup routine.  The refcon can be anything.  The disassembler does not look at it.
  363.     
  364.     The caller also can control some aspects of the formatting with the DisassemblerOptions
  365.     as described above.  The options also specify the target architecture; Power, PowerPC32,
  366.     PowerPC64, or PowerPC601.
  367.     
  368.     The disassembler returns as its function result the DisassemblerStatus.  This may be
  369.     tested for 0 ("false" or DisInvalid defined below) to find out if an invalid instruction
  370.     was detected.  For valid instructions, the DisassemblerStatus is non zero and indicates
  371.     various attributes about the instruction as follows:                                                                    *}
  372.     
  373. {* The "lookup" substitution routine for the objects is defined as follows:
  374.  
  375. FUNCTION DisassemblerLookups(            refCon                    :    UNIV Ptr,
  376.                                                              VAR    cia                            :    LongInt, 
  377.                                                                     lookupType            :    DisassemblerLookupType,
  378.                                                                     thingToReplace    :    DisLookupValue) : CStringPtr; C;
  379.  
  380.     where, refCon                  = A "reference constant" that can be used as a communication link
  381.                                                      between the lookup routine and the caller of the disassembler.
  382.                                                      It is the same refCon passed to the disassembler.
  383.  
  384.                     cia                       = The instruction address passed to the disassembler.
  385.  
  386.                     lookupType and
  387.                     thingToReplace = The kind of object and the associated value of that object to be
  388.                                                      replaced.  As defined by DisLookupValue, the thingToReplace has
  389.                                                      the following value for each lookupType.
  390.  
  391.                                                      lookupType                                                value            
  392.                                                      ============================================= 
  393.                                                      Disassembler_Lookup_GPRegister        0:31                
  394.                                                      Disassembler_Lookup_FPRegister        0:31                
  395.                                                      Disassembler_Lookup_UImmediate        integer    
  396.                                                      Disassembler_Lookup_SImmediate        integer        
  397.                                    Disassembler_Lookup_AbsAddress        address [1]
  398.                                                      Disassembler_Lookup_RelAddress        address [2]
  399.                                                      Disassembler_Lookup_RegOffset        D + Ra  [3]
  400.                                                      Disassembler_Lookup_SPRegister        spr            [4]
  401.                                                      Disassembler_Lookup_VecRegister  0:31    [5]
  402.                                                    =============================================
  403.  
  404.                                                       Notes: 
  405.                                                      
  406.                                                      [1] This is an absolute target branch address, i.e., the "a" bit
  407.                                                               in the branch instruction IS set.  The passed absAddress
  408.                                                              is the address contained in the instruction.
  409.                                                              
  410.                                                      [2] This is a relocatable target branch address, i.e., the "a"
  411.                                                               bit in the branch instruction was NOT set.  The relAddress
  412.                                                              is relative to the current instruction address adjusted
  413.                                                              by the dstAdjust.  Thus,
  414.                                                              
  415.                                                              relAddress = destinationAddress + dstAdjust + cia
  416.                                                              
  417.                                                              where cia is the current instruction address, i.e, the value
  418.                                                              of the instruction address passed to the disassembler.
  419.                                                                             
  420.                                                      [3] Both the offset (D) and base register (Ra) are passed.  The
  421.                                                               DisLookupValue.regOffset value defines how they are packed
  422.                                                              in the thingToReplace.  The offset should be assigned to a
  423.                                                              long to get its true 32-bit value.  It is valid to pass it
  424.                                                              as a signed short since the instruction field from which it
  425.                                                              came is never more than 16 bits wide.
  426.                                                      
  427.                                                      [4] The lookup for SPRs is slightly different in that it is only
  428.                                                               done as an ESCAPE mechanism, i.e., only when the SPR number is
  429.                                                              NOT one of the predefined Power, 601, PowerPC32, or
  430.                                                              PowerPC64 SPR names.  This is done because a different
  431.                                                              PowerPC architectures can have additional SPRs specific to
  432.                                                              those architectures!  The lookup routine is called only if
  433.                                                              the SPR is NOT one of the following predefined numbers:
  434.                                                                     
  435.                                                                 0 MQ      272 SPRG0   528 IBAT0U   536 DBAT0U   1008 HID0
  436.                                                                 1 XER     273 SPRG1   529 IBAT0L   537 DBAT0L   1009 HID1
  437.                                                                 4 RTCU    274 SPRG2   530 IBAT1U   538 DBAT1U   1010 IABR
  438.                                                                 5 RTCL    275 SPRG3   531 IBAT1L   539 DBAT1L   1013 DABR
  439.                                                                 6 DEC     280 ASR     532 IBAT2U   540 DBAT2U   1023 PIR
  440.                                                                 8 LR      282 EAR     533 IBAT2L   541 DBAT2L
  441.                                                                 9 CTR     284 TB      534 IBAT3U   542 DBAT3U
  442.                                                              18 DSIAR   285 TBU     535 IBAT3L   543 DBAT3L
  443.                                                              19 DAR     287 PVR
  444.                                                              22 DEC
  445.                                                              25 SDR1
  446.                                                              26 SRR0
  447.                                                              27 SRR1
  448.                                                             
  449.                                                              Not all of these SPRs are valid for all targets.  The
  450.                                                              disassembler will check to see if these SPRs are valid for
  451.                                                              the specified target architecture.  If they are not, the SPR
  452.                                                              number is treated as an invalid field and processed
  453.                                                              according to the Disassemble_FieldErr option, i.e., it’s
  454.                                                              accepted but returns a status warning, or the instruction is
  455.                                                              treated as invalid (“DC.L 0xXXXXXXXX”).
  456.  
  457.                                                              SPR numbers which are not on the list, and also do not have
  458.                                                              a lookup substitution name, are always accepted.  But since
  459.                                                              there is no way for the disassembler to validate these
  460.                                                              against the target, the Disassembler_InvSprMaybe return
  461.                                                              status flag will be set.
  462.                                                      
  463.                                                      [5] The vector registers are only used if the Disassemble_Vec
  464.                                                          was passed in the options.                                                                *}
  465.                                                              
  466. {* NOTES: 1. The disassembler library uses the convention that, with the exception of     *}
  467. {*                     the called routine name itself, i.e., "ppcDisassembler", all externally         *}
  468. {*                     visible names (linker symbols and macro names) begin with the letters "dis"*}
  469. {*                      (in any case).  The user should keep this in mind to avoid possible name     *}
  470. {*                      conflicts.                                                                                                                                    *}
  471.  
  472. {*                2. Except for statically declared (read only) tables, the disassembler uses no*}
  473. {*                     other global data.                                                                                                                    *}
  474.  
  475. {*                3. The disassembler is fully self contained in that it has no explicit                 *}
  476. {*                     references to any runtime library routines (e.g., strcpy).  There may,         *}
  477. {*                     however, be implicit references generated by the (C) compiler.                            *}
  478.  
  479. {*                4. The disassembler is written in standard ANSI C making it possible to easily*}
  480. {*                     port to other platforms.                                                                                                        *}
  481.  
  482.  
  483. {$ALIGN RESET}
  484. {$POP}
  485.  
  486. {$SETC UsingIncludes := DisassemblerIncludes}
  487.  
  488. {$ENDC} {__DISASSEMBLER__}
  489.  
  490. {$IFC NOT UsingIncludes}
  491.  END.
  492. {$ENDC}
  493.